﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RosInterface
{
    public class RosConfiguration
    {
        public Uri MasterUri;
        public string HostName, SelfIp;

        /// <summary>
        /// 连接到Ros所需的配置信息
        /// </summary>
        /// <param name="master">$ROS_MASTER_URI</param>
        /// <param name="host">$ROS_HOSTNAME</param>
        /// <param name="selfip">$ROS_IP</param>
        public RosConfiguration(Uri master, string host, string selfip)
        {
            MasterUri = master;
            HostName = host;
            SelfIp = selfip;
        }

        /// <summary>
        /// 从环境变量获取默认的RosConfiguration
        /// <para>$ROS_MASTER_URI -> MasterUri</para>
        /// <para>$ROS_HOSTNAME   -> HostName</para>
        /// <para>$ROS_IP         -> SelfIp</para>
        /// </summary>
        /// <returns>依据环境变量构建的RosConfiguration</returns>
        public static RosConfiguration FromEnv()
        {
            return new RosConfiguration(
                new Uri(Environment.GetEnvironmentVariable("ROS_MASTER_URI")),
                Environment.GetEnvironmentVariable("ROS_HOSTNAME"),
                Environment.GetEnvironmentVariable("ROS_IP")
            );
        }
    }
}
